﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Resto.CostControl.Core.Domain.Model;
using Resto.CostControl.Core.Cache;
using Resto.CostControl.Core.Facade.MaterialModule.DataTransferObject;

namespace Resto.CostControl.Core.Facade.SupplierModule.DataTransferObject
{
    /// <summary>
    /// 原材料采购单的项DTO
    /// </summary>
    [Serializable]
    public class MaterialPurchaseItemDTO
    {
        #region 构造函数

        public MaterialPurchaseItemDTO() { }

        internal MaterialPurchaseItemDTO(MaterialPurchaseItem item)
        {
            this.ID = item.ID;
            this.Price = item.Price;
            this.OrderCount = item.OrderCount;
            this.DeliveryCount = item.DeliveryCount;
            this.StorageCount = item.StorageCount;
            this.MaterialId = item.MaterialID;

            this.Material = MaterialDTOCache.Get(item.MaterialID);


        }

        #endregion

        #region 基本属性

        public string ID { get; set; }

        /// <summary>
        /// 价格
        /// </summary>
        public decimal Price { get; set; }

        /// <summary>
        /// 品名Id
        /// </summary>
        public string MaterialId { get; set; }

        public MaterialDTO Material { get; protected set; }
        
        /// <summary>
        /// 订购数
        /// </summary>
        public decimal OrderCount { get; set; }

        /// <summary>
        /// 发货数
        /// </summary>
        public decimal? DeliveryCount { get; set; }

        /// <summary>
        /// 入库数
        /// </summary>
        public decimal? StorageCount { get; set; }

        #endregion

        #region 方法

        internal MaterialPurchaseItem ToMaterialPurchaseItem()
        {
            MaterialPurchaseItem item = new MaterialPurchaseItem();
            CopyToMaterialPurchaseItem(item);
            return item;
        }

        internal void CopyToMaterialPurchaseItem(MaterialPurchaseItem item)
        {
            item.MaterialID = this.MaterialId;
            item.Price = this.Price;
            item.OrderCount = this.OrderCount;
            item.DeliveryCount = this.DeliveryCount;
            item.StorageCount = this.StorageCount;
        }

        #endregion
    }
}
